/*
 * @Author: YNT 2501512800@qq.com
 * @Date: 2022-07-25 00:06:36
 * @LastEditors: YNT 2501512800@qq.com
 * @LastEditTime: 2022-10-25 16:04:01
 * @FilePath: \22-03-19 智慧社区\pages\toolbar\passDetail\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// pages/toolbar/passDetail/index.js
import { comm } from '../../../behaviors/index'
import SpecialModel from '../../../api/special'
Page({
  behaviors: [comm],
  data: {
    nvabarData: {
      navigationBarTextStyle: 'black', // 胶囊主题 white || black
      navigationBarBackground: '#ffffff', // 导航栏背景色
      navigationBarTitleText: '访客通行',
    },
    vistor_name: '',
    vistor_phone: '',
    sex: '',
    date: '',
    is_driver: '',
    car_num: '',
    qr_img: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading()
    let id = options.id
    let _that = this
    this.setData({
      id,
    })
    SpecialModel.passDetail(id)
      .then(({ data }) => {
        _that.setData({
          vistor_name: data.vistor_name,
          vistor_phone: data.vistor_phone,
          sex: data.sex == '1' ? '男' : '女',
          vistor_matter_name: data.vistor_matter_name,
          date: data.date,
          is_driver: data.is_driver ? '是' : '否',
          car_num: data.car_num,
          qr_img: data.qr_img,
        })
      })
      .catch((err) => {})
      .finally(() => wx.hideLoading())
  },

  // 页面转发
  onShareAppMessage: function ({ from }) {
    let { id } = this.data
    switch (from) {
      case 'button': // 页内按钮转发
        return {
          title: '通行证',
          path: `/pages/toolbar/passDetail/index?id=${id}`,
        }
      default:
        // 右上角菜单“转发”
        return {}
    }
  },
})
